package com.tencent.servlet;

import com.tencent.pojo.Student;
import com.tencent.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: Fame
 * @date: 2022-06-20 15:42
 * @description:
 */
@WebServlet("/insert")
public class MyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        int age = Integer.parseInt(req.getParameter("age"));
        String phone = req.getParameter("phone");
        String address = req.getParameter("address");

        Student student = new Student(null,name, age, phone, address);
        System.out.println(new StudentServiceImpl().insert(student));
        req.getRequestDispatcher("student").forward(req,resp);
    }
}
